package com.bkgy.modular.tbdsjc621sameedgeresult.service;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bkgy.excelhandle.PlanExcelHandlerImpl;
import com.bkgy.modular.calsidata.entity.TbEdge;
import com.bkgy.modular.datacollect_bx.bean.JDataSave621;
import com.bkgy.modular.tbdsjc621sameedgeresult.dao.TbDsjC621SameEdgeResultDao;
import com.bkgy.modular.tbdsjc621sameedgeresult.entity.*;
import com.bkgy.sys.common.entity.ResultData;
import com.bkgy.util.ExcelUtils;
import com.bkgy.util.ExcelUtilsPOI;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ResourceUtils;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class TbDsjC621SameEdgeResultService {

    @Autowired
    private TbDsjC621SameEdgeResultDao tbDsjC621SameEdgeResultDao;

    @Resource
    private MongoTemplate mongoTemplate;

    public ResultData findDataTbDsjC621SameEdgeResultServiceByPage(String data) {
        try {
            JTbDsjC621SameEdgeResult jTbDsjC621SameEdgeResult = JSON.parseObject(data, JTbDsjC621SameEdgeResult.class);
            JSONObject jsonObject = null;
            Integer pageIndex = jTbDsjC621SameEdgeResult.getPageIndex();
            Integer pageSize = jTbDsjC621SameEdgeResult.getPageSize();

            if (null == pageIndex || null == pageSize) {
                return ResultData.ResultDataFaultSelf("分页参数没有传", null);
            }
            LambdaQueryWrapper<TbDsjC621SameEdgeResult> wrapper = new LambdaQueryWrapper<>();

            if (null != jTbDsjC621SameEdgeResult.getCondition()) {
                jsonObject = JSON.parseObject(jTbDsjC621SameEdgeResult.getCondition().toString());
            }

            String dbegin = null; //开始时间
            if (StringUtils.hasText(jsonObject.getString("dbegin"))) {
                dbegin = jsonObject.getString("dbegin");
                wrapper.ge(TbDsjC621SameEdgeResult::getCreatetime, dbegin);
            }
            String dend = null; //结束时间
            if (StringUtils.hasText(jsonObject.getString("dend"))) {
                dend = jsonObject.getString("dend");
                wrapper.le(TbDsjC621SameEdgeResult::getCreatetime, dend);
            }

            String coil_id = null;
            if (StringUtils.hasText(jsonObject.getString("coil_id"))) {
                coil_id = jsonObject.getString("coil_id");
                wrapper.like(TbDsjC621SameEdgeResult::getCoil_id, coil_id);
            }

            String hot_id = null;
            if (StringUtils.hasText(jsonObject.getString("hot_id"))) {
                hot_id = jsonObject.getString("hot_id");
                wrapper.like(TbDsjC621SameEdgeResult::getHot_coil_id, hot_id);
            }

            String ex_thk1 = null;  //产品厚度----开始
            if (StringUtils.hasText(jsonObject.getString("ex_thk1"))) {
                ex_thk1 = jsonObject.getString("ex_thk1");
                wrapper.ge(TbDsjC621SameEdgeResult::getEx_thk, ex_thk1);
            }

            String ex_thk2 = null;  //产品厚度---结束
            if (StringUtils.hasText(jsonObject.getString("ex_thk2"))) {
                ex_thk2 = jsonObject.getString("ex_thk2");
                wrapper.le(TbDsjC621SameEdgeResult::getEx_thk, ex_thk2);
            }

            String en_wid1 = null;  //原料宽度----开始
            if (StringUtils.hasText(jsonObject.getString("en_wid1"))) {
                en_wid1 = jsonObject.getString("en_wid1");
                wrapper.ge(TbDsjC621SameEdgeResult::getEn_wid, en_wid1);
            }


            String en_wid2 = null;  //原料宽度----结束
            if (StringUtils.hasText(jsonObject.getString("en_wid2"))) {
                en_wid2 = jsonObject.getString("en_wid2");
                wrapper.le(TbDsjC621SameEdgeResult::getEn_wid, en_wid2);

            }

            String en_thk1 = null;  //原料厚度----开始
            if (StringUtils.hasText(jsonObject.getString("en_thk1"))) {
                en_thk1 = jsonObject.getString("en_thk1");
                wrapper.ge(TbDsjC621SameEdgeResult::getEn_thk, en_thk1);
            }

            String en_thk2 = null;  //原料厚度----结束
            if (StringUtils.hasText(jsonObject.getString("en_thk2"))) {
                en_thk2 = jsonObject.getString("en_thk2");
                wrapper.le(TbDsjC621SameEdgeResult::getEn_thk, en_thk2);
            }

            String ele_si1 = null;  //硅含量---开始
            if (StringUtils.hasText(jsonObject.getString("ele_si1"))) {
                ele_si1 = jsonObject.getString("ele_si1");
                wrapper.ge(TbDsjC621SameEdgeResult::getEle_si, ele_si1);
            }
            String ele_si2 = null;  //硅含量---结束
            if (StringUtils.hasText(jsonObject.getString("ele_si2"))) {
                ele_si2 = jsonObject.getString("ele_si2");
                wrapper.le(TbDsjC621SameEdgeResult::getEle_si, ele_si2);
            }

            String steelgrade = null;  //钢种
            if (StringUtils.hasText(jsonObject.getString("steelgrade"))) {
                steelgrade = jsonObject.getString("steelgrade");
                wrapper.eq(TbDsjC621SameEdgeResult::getSteelgrade, steelgrade);
            }
            wrapper.orderByDesc(TbDsjC621SameEdgeResult::getCreatetime);

            //分页查询
            Page<TbDsjC621SameEdgeResult> page = new Page<>(pageIndex, pageSize);
            Page<TbDsjC621SameEdgeResult> resultPage = tbDsjC621SameEdgeResultDao.selectPage(page, wrapper);
            List<TbDsjC621SameEdgeResult> listForPage = resultPage.getRecords();

            //不分页查询
            //List<TbDsjC621SameEdgeResult> list = tbDsjC621SameEdgeResultDao.selectList(wrapper);
            List<TbDsjC621SameEdgeResult> list1 = tbDsjC621SameEdgeResultDao.selectList(wrapper);
            Integer count = list1.size();
            List<TbDsjC621SameEdgeResult> list = listForPage;
            SteelSame steelSame = new SteelSame();

            //同板差10头
            Double same10HeadMax = 0.0;
            String same10HeadMaxColiId = null;
            String same10HeadMaxHotColiId = null;

            Double same10HeadMin = 0.0;
            String same10HeadMinColiId = null;
            String same10HeadMinHotColiId = null;

            Double same10HeadAllLen = 0.0;
            Double same10HeadAvgLen = 0.0;

            //中
            Double same10MidMax = 0.0;
            String same10MidMaxColiId = null;
            String same10MidMaxHotColiId = null;

            Double same10MidMin = 0.0;
            String same10MidMinColiId = null;
            String same10MidMinHotColiId = null;

            Double same10MidAllLen = 0.0;
            Double same10MidAvgLen = 0.0;

            //尾
            Double same10TailMax = 0.0;
            String same10TailMaxColiId = null;
            String same10TailMaxHotColiId = null;

            Double same10TailMin = 0.0;
            String same10TailMinColiId = null;
            String same10TailMinHotColiId = null;

            Double same10TailAllLen = 0.0;
            Double same10TailAvgLen = 0.0;
            //同板差15
            Double same15HeadMax = 0.0;
            String same15HeadMaxColiId = null;
            String same15HeadMaxHotColiId = null;

            Double same15HeadMin = 0.0;
            String same15HeadMinColiId = null;
            String same15HeadMinHotColiId = null;

            Double same15HeadAllLen = 0.0;
            Double same15HeadAvgLen = 0.0;

            //中
            Double same15MidMax = 0.0;
            String same15MidMaxColiId = null;
            String same15MidMaxHotColiId = null;

            Double same15MidMin = 0.0;
            String same15MidMinColiId = null;
            String same15MidMinHotColiId = null;

            Double same15MidAllLen = 0.0;
            Double same15MidAvgLen = 0.0;

            //尾
            Double same15TailMax = 0.0;
            String same15TailMaxColiId = null;
            String same15TailMaxHotColiId = null;

            Double same15TailMin = 0.0;
            String same15TailMinColiId = null;
            String same15TailMinHotColiId = null;

            Double same15TailAllLen = 0.0;
            Double same15TailAvgLen = 0.0;
            //边降
            Double edgeHeadMax = 0.0;
            String edgeHeadMaxColiId = null;
            String edgeHeadMaxHotColiId = null;

            Double edgeHeadMin = 0.0;
            String edgeHeadMinColiId = null;
            String edgeHeadMinHotColiId = null;

            Double edgeHeadAllLen = 0.0;
            Double edgeHeadAvgLen = 0.0;

            //中
            Double edgeMidMax = 0.0;
            String edgeMidMaxColiId = null;
            String edgeMidMaxHotColiId = null;

            Double edgeMidMin = 0.0;
            String edgeMidMinColiId = null;
            String edgeMidMinHotColiId = null;

            Double edgeMidAllLen = 0.0;
            Double edgeMidAvgLen = 0.0;

            //尾
            Double edgeTailMax = 0.0;
            String edgeTailMaxColiId = null;
            String edgeTailMaxHotColiId = null;

            Double edgeTailMin = 0.0;
            String edgeTailMinColiId = null;
            String edgeTailMinHotColiId = null;

            Double edgeTailAllLen = 0.0;
            Double edgeTailAvgLen = 0.0;



            for (TbDsjC621SameEdgeResult entity : list) {
                //10
                if (entity.getSameplate10_head_tole_max_value() != null && entity.getSameplate10_head_tole_max_value() > same10HeadMax) {
                    same10HeadMax = entity.getSameplate10_head_tole_max_value();
                    same10HeadMaxColiId = entity.getCoil_id();
                    same10HeadMaxHotColiId = entity.getHot_coil_id();
                }

                if (entity.getSameplate10_head_tole_min_value() != null && entity.getSameplate10_head_tole_min_value() > same10HeadMin) {
                    same10HeadMin = entity.getSameplate10_head_tole_min_value();
                    same10HeadMinColiId = entity.getCoil_id();
                    same10HeadMinHotColiId = entity.getHot_coil_id();
                }

                if (entity.getSameplate10_mid_tole_max_value() != null && entity.getSameplate10_mid_tole_max_value() > same10MidMax) {
                    same10MidMax = entity.getSameplate10_mid_tole_max_value();
                    same10MidMaxColiId = entity.getCoil_id();
                    same10MidMaxHotColiId = entity.getHot_coil_id();
                }

                if (entity.getSameplate10_mid_tole_min_value() != null && entity.getSameplate10_mid_tole_min_value() > same10MidMin) {
                    same10MidMin = entity.getSameplate10_mid_tole_min_value();
                    same10MidMinColiId = entity.getCoil_id();
                    same10MidMinHotColiId = entity.getHot_coil_id();
                }
                if (entity.getSameplate10_tail_tole_max_value() != null && entity.getSameplate10_tail_tole_max_value() > same10TailMax) {
                    same10TailMax = entity.getSameplate10_tail_tole_max_value();
                    same10TailMaxColiId = entity.getCoil_id();
                    same10TailMaxHotColiId = entity.getHot_coil_id();
                }

                if (entity.getSameplate10_tail_tole_min_value() != null && entity.getSameplate10_tail_tole_min_value() > same10TailMin) {
                    same10TailMin = entity.getSameplate10_tail_tole_min_value();
                    same10TailMinColiId = entity.getCoil_id();
                    same10TailMinHotColiId = entity.getHot_coil_id();
                }
                //统计头中尾最大最小总长
                if (entity.getSameplate10_total_head_tole_abs_len() != null) {
                    same10HeadAllLen +=entity.getSameplate10_total_head_tole_abs_len();
                }
                if (entity.getSameplate10_total_mid_tole_abs_len() != null) {
                    same10MidAllLen +=entity.getSameplate10_total_mid_tole_abs_len();
                }
                if (entity.getSameplate10_total_tail_tole_abs_len() != null) {
                    same10TailAllLen +=entity.getSameplate10_total_tail_tole_abs_len();
                }





                //15
                if (entity.getSameplate15_head_tole_max_value() != null && entity.getSameplate15_head_tole_max_value() > same15HeadMax) {
                    same15HeadMax = entity.getSameplate15_head_tole_max_value();
                    same15HeadMaxColiId = entity.getCoil_id();
                    same15HeadMaxHotColiId = entity.getHot_coil_id();
                }

                if (entity.getSameplate15_head_tole_min_value() != null && entity.getSameplate15_head_tole_min_value() > same15HeadMin) {
                    same15HeadMin = entity.getSameplate15_head_tole_min_value();
                    same15HeadMinColiId = entity.getCoil_id();
                    same15HeadMinHotColiId = entity.getHot_coil_id();
                }

                if (entity.getSameplate15_mid_tole_max_value() != null && entity.getSameplate15_mid_tole_max_value() > same15MidMax) {
                    same15MidMax = entity.getSameplate15_mid_tole_max_value();
                    same15MidMaxColiId = entity.getCoil_id();
                    same15MidMaxHotColiId = entity.getHot_coil_id();
                }

                if (entity.getSameplate15_mid_tole_min_value() != null && entity.getSameplate15_mid_tole_min_value() > same15MidMin) {
                    same15MidMin = entity.getSameplate15_mid_tole_min_value();
                    same15MidMinColiId = entity.getCoil_id();
                    same15MidMinHotColiId = entity.getHot_coil_id();
                }
                if (entity.getSameplate15_tail_tole_max_value() != null && entity.getSameplate15_tail_tole_max_value() > same15TailMax) {
                    same15TailMax = entity.getSameplate15_tail_tole_max_value();
                    same15TailMaxColiId = entity.getCoil_id();
                    same15TailMaxHotColiId = entity.getHot_coil_id();
                }

                if (entity.getSameplate15_tail_tole_min_value() != null && entity.getSameplate15_tail_tole_min_value() > same15TailMin) {
                    same15TailMin = entity.getSameplate15_tail_tole_min_value();
                    same15TailMinColiId = entity.getCoil_id();
                    same15TailMinHotColiId = entity.getHot_coil_id();
                }
                //统计头中尾最大最小总长
                if (entity.getSameplate15_total_head_tole_abs_len() != null) {
                    same15HeadAllLen +=entity.getSameplate15_total_head_tole_abs_len();
                }
                if (entity.getSameplate15_total_mid_tole_abs_len() != null) {
                    same15MidAllLen +=entity.getSameplate15_total_mid_tole_abs_len();
                }
                if (entity.getSameplate15_total_tail_tole_abs_len() != null) {
                    same15TailAllLen +=entity.getSameplate15_total_tail_tole_abs_len();
                }
                //边降
                if (entity.getEdge_head_tole_max_value() != null && entity.getEdge_head_tole_max_value() > edgeHeadMax) {
                    edgeHeadMax = entity.getEdge_head_tole_max_value();
                    edgeHeadMaxColiId = entity.getCoil_id();
                    edgeHeadMaxHotColiId = entity.getHot_coil_id();
                }

                if (entity.getEdge_head_tole_min_value() != null && entity.getEdge_head_tole_min_value() > edgeHeadMin) {
                    edgeHeadMin = entity.getEdge_head_tole_min_value();
                    edgeHeadMinColiId = entity.getCoil_id();
                    edgeHeadMinHotColiId = entity.getHot_coil_id();
                }

                if (entity.getEdge_mid_tole_max_value() != null && entity.getEdge_mid_tole_max_value() > edgeMidMax) {
                    edgeMidMax = entity.getEdge_mid_tole_max_value();
                    edgeMidMaxColiId = entity.getCoil_id();
                    edgeMidMaxHotColiId = entity.getHot_coil_id();
                }

                if (entity.getEdge_mid_tole_min_value() != null && entity.getEdge_mid_tole_min_value() > edgeMidMin) {
                    edgeMidMin = entity.getEdge_mid_tole_min_value();
                    edgeMidMinColiId = entity.getCoil_id();
                    edgeMidMinHotColiId = entity.getHot_coil_id();
                }
                if (entity.getEdge_tail_tole_max_value() != null && entity.getEdge_tail_tole_max_value() > edgeTailMax) {
                    edgeTailMax = entity.getEdge_tail_tole_max_value();
                    edgeTailMaxColiId = entity.getCoil_id();
                    edgeTailMaxHotColiId = entity.getHot_coil_id();
                }

                if (entity.getEdge_tail_tole_min_value() != null && entity.getEdge_tail_tole_min_value() > edgeTailMin) {
                    edgeTailMin = entity.getEdge_tail_tole_min_value();
                    edgeTailMinColiId = entity.getCoil_id();
                    edgeTailMinHotColiId = entity.getHot_coil_id();
                }
                //统计头中尾最大最小总长
                if (entity.getEdge_total_head_tole_abs_len() != null) {
                    edgeHeadAllLen +=entity.getEdge_total_head_tole_abs_len();
                }
                if (entity.getEdge_total_mid_tole_abs_len() != null) {
                    edgeMidAllLen +=entity.getEdge_total_mid_tole_abs_len();
                }
                if (entity.getEdge_total_tail_tole_abs_len() != null) {
                    edgeTailAllLen +=entity.getEdge_total_tail_tole_abs_len();
                }
            }
            //10求均值
            if(null!=same10HeadAllLen){
                same10HeadAvgLen = same10HeadAllLen/list.size();
            }
            if(null!=same10MidAllLen){
                same10MidAvgLen = same10MidAllLen/list.size();
            }
            if(null!=same10TailAllLen){
                same10TailAvgLen = same10TailAllLen/list.size();
            }
            //15求均值
            if(null!=same15HeadAllLen){
                same15HeadAvgLen = same15HeadAllLen/list.size();
            }
            if(null!=same15MidAllLen){
                same15MidAvgLen = same15MidAllLen/list.size();
            }
            if(null!=same15TailAllLen){
                same15TailAvgLen = same15TailAllLen/list.size();
            }
            //边降求均值
            if(null!=edgeHeadAllLen){
                edgeHeadAvgLen = edgeHeadAllLen/list.size();
            }
            if(null!=edgeMidAllLen){
                edgeMidAvgLen = edgeMidAllLen/list.size();
            }
            if(null!=edgeTailAllLen){
                edgeTailAvgLen = edgeTailAllLen/list.size();
            }
            //分等级求总长
            Double same10WsAAllLen = list.stream().filter(x->!StringUtils.isEmpty(x.getSameplate10_ws_a_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getSameplate10_ws_a_abs_len).sum();
            Double same10WsBAllLen = list.stream().filter(x->!StringUtils.isEmpty(x.getSameplate10_ws_b_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getSameplate10_ws_b_abs_len).sum();
            Double same10WsCAllLen = list.stream().filter(x->!StringUtils.isEmpty(x.getSameplate10_ws_c_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getSameplate10_ws_c_abs_len).sum();
            Double same10WsDAllLen = list.stream().filter(x->!StringUtils.isEmpty(x.getSameplate10_ws_d_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getSameplate10_ws_d_abs_len).sum();
            Double same10WsEAllLen = list.stream().filter(x->!StringUtils.isEmpty(x.getSameplate10_ws_e_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getSameplate10_ws_e_abs_len).sum();

            Double same10DsAAllLen = list.stream().filter(x->!StringUtils.isEmpty(x.getSameplate10_ds_a_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getSameplate10_ds_a_abs_len).sum();
            Double same10DsBAllLen = list.stream().filter(x->!StringUtils.isEmpty(x.getSameplate10_ds_b_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getSameplate10_ds_b_abs_len).sum();
            Double same10DsCAllLen = list.stream().filter(x->!StringUtils.isEmpty(x.getSameplate10_ds_c_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getSameplate10_ds_c_abs_len).sum();
            Double same10DsDAllLen = list.stream().filter(x->!StringUtils.isEmpty(x.getSameplate10_ds_d_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getSameplate10_ds_d_abs_len).sum();
            Double same10DsEAllLen = list.stream().filter(x->!StringUtils.isEmpty(x.getSameplate10_ds_e_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getSameplate10_ds_e_abs_len).sum();

            Double same15WsAAllLen = list.stream().filter(x->!StringUtils.isEmpty(x.getSameplate15_ws_a_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getSameplate15_ws_a_abs_len).sum();
            Double same15WsBAllLen = list.stream().filter(x->!StringUtils.isEmpty(x.getSameplate15_ws_b_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getSameplate15_ws_b_abs_len).sum();
            Double same15WsCAllLen = list.stream().filter(x->!StringUtils.isEmpty(x.getSameplate15_ws_c_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getSameplate15_ws_c_abs_len).sum();
            Double same15WsDAllLen = list.stream().filter(x->!StringUtils.isEmpty(x.getSameplate15_ws_d_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getSameplate15_ws_d_abs_len).sum();
            Double same15WsEAllLen = list.stream().filter(x->!StringUtils.isEmpty(x.getSameplate15_ws_e_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getSameplate15_ws_e_abs_len).sum();

            Double same15DsAAllLen = list.stream().filter(x->!StringUtils.isEmpty(x.getSameplate15_ds_a_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getSameplate15_ds_a_abs_len).sum();
            Double same15DsBAllLen = list.stream().filter(x->!StringUtils.isEmpty(x.getSameplate15_ds_b_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getSameplate15_ds_b_abs_len).sum();
            Double same15DsCAllLen = list.stream().filter(x->!StringUtils.isEmpty(x.getSameplate15_ds_c_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getSameplate15_ds_c_abs_len).sum();
            Double same15DsDAllLen = list.stream().filter(x->!StringUtils.isEmpty(x.getSameplate15_ds_d_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getSameplate15_ds_d_abs_len).sum();
            Double same15DsEAllLen = list.stream().filter(x->!StringUtils.isEmpty(x.getSameplate15_ds_e_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getSameplate15_ds_e_abs_len).sum();

            Double edgeWsAAllLen = list.stream().filter(x->!StringUtils.isEmpty(x.getEdge_ws_a_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getEdge_ws_a_abs_len).sum();
            Double edgeWsBAllLen = list.stream().filter(x->!StringUtils.isEmpty(x.getEdge_ws_b_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getEdge_ws_b_abs_len).sum();
            Double edgeWsCAllLen = list.stream().filter(x->!StringUtils.isEmpty(x.getEdge_ws_c_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getEdge_ws_c_abs_len).sum();
            Double edgeWsDAllLen = list.stream().filter(x->!StringUtils.isEmpty(x.getEdge_ws_d_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getEdge_ws_d_abs_len).sum();
            Double edgeWsEAllLen = list.stream().filter(x->!StringUtils.isEmpty(x.getEdge_ws_e_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getEdge_ws_e_abs_len).sum();

            Double edgeDsAAllLen = list.stream().filter(x->!StringUtils.isEmpty(x.getEdge_ds_a_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getEdge_ds_a_abs_len).sum();
            Double edgeDsBAllLen = list.stream().filter(x->!StringUtils.isEmpty(x.getEdge_ds_b_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getEdge_ds_b_abs_len).sum();
            Double edgeDsCAllLen = list.stream().filter(x->!StringUtils.isEmpty(x.getEdge_ds_c_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getEdge_ds_c_abs_len).sum();
            Double edgeDsDAllLen = list.stream().filter(x->!StringUtils.isEmpty(x.getEdge_ds_d_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getEdge_ds_d_abs_len).sum();
            Double edgeDsEAllLen = list.stream().filter(x->!StringUtils.isEmpty(x.getEdge_ds_e_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getEdge_ds_e_abs_len).sum();
            
            //分等级求均值
            Double same10WsAAvgLen = list.stream().filter(x->!StringUtils.isEmpty(x.getSameplate10_ws_a_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getSameplate10_ws_a_abs_len).average().orElse(0.0);
            Double same10WsBAvgLen = list.stream().filter(x->!StringUtils.isEmpty(x.getSameplate10_ws_b_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getSameplate10_ws_b_abs_len).average().orElse(0.0);
            Double same10WsCAvgLen = list.stream().filter(x->!StringUtils.isEmpty(x.getSameplate10_ws_c_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getSameplate10_ws_c_abs_len).average().orElse(0.0);
            Double same10WsDAvgLen = list.stream().filter(x->!StringUtils.isEmpty(x.getSameplate10_ws_d_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getSameplate10_ws_d_abs_len).average().orElse(0.0);
            Double same10WsEAvgLen = list.stream().filter(x->!StringUtils.isEmpty(x.getSameplate10_ws_e_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getSameplate10_ws_e_abs_len).average().orElse(0.0);
            Double same10DsAAvgLen = list.stream().filter(x->!StringUtils.isEmpty(x.getSameplate10_ds_a_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getSameplate10_ds_a_abs_len).average().orElse(0.0);
            Double same10DsBAvgLen = list.stream().filter(x->!StringUtils.isEmpty(x.getSameplate10_ds_b_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getSameplate10_ds_b_abs_len).average().orElse(0.0);
            Double same10DsCAvgLen = list.stream().filter(x->!StringUtils.isEmpty(x.getSameplate10_ds_c_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getSameplate10_ds_c_abs_len).average().orElse(0.0);
            Double same10DsDAvgLen = list.stream().filter(x->!StringUtils.isEmpty(x.getSameplate10_ds_d_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getSameplate10_ds_d_abs_len).average().orElse(0.0);
            Double same10DsEAvgLen = list.stream().filter(x->!StringUtils.isEmpty(x.getSameplate10_ds_e_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getSameplate10_ds_e_abs_len).average().orElse(0.0);

            Double same15WsAAvgLen = list.stream().filter(x->!StringUtils.isEmpty(x.getSameplate15_ws_a_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getSameplate15_ws_a_abs_len).average().orElse(0.0);
            Double same15WsBAvgLen = list.stream().filter(x->!StringUtils.isEmpty(x.getSameplate15_ws_b_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getSameplate15_ws_b_abs_len).average().orElse(0.0);
            Double same15WsCAvgLen = list.stream().filter(x->!StringUtils.isEmpty(x.getSameplate15_ws_c_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getSameplate15_ws_c_abs_len).average().orElse(0.0);
            Double same15WsDAvgLen = list.stream().filter(x->!StringUtils.isEmpty(x.getSameplate15_ws_d_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getSameplate15_ws_d_abs_len).average().orElse(0.0);
            Double same15WsEAvgLen = list.stream().filter(x->!StringUtils.isEmpty(x.getSameplate15_ws_e_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getSameplate15_ws_e_abs_len).average().orElse(0.0);
            Double same15DsAAvgLen = list.stream().filter(x->!StringUtils.isEmpty(x.getSameplate15_ds_a_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getSameplate15_ds_a_abs_len).average().orElse(0.0);
            Double same15DsBAvgLen = list.stream().filter(x->!StringUtils.isEmpty(x.getSameplate15_ds_b_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getSameplate15_ds_b_abs_len).average().orElse(0.0);
            Double same15DsCAvgLen = list.stream().filter(x->!StringUtils.isEmpty(x.getSameplate15_ds_c_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getSameplate15_ds_c_abs_len).average().orElse(0.0);
            Double same15DsDAvgLen = list.stream().filter(x->!StringUtils.isEmpty(x.getSameplate15_ds_d_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getSameplate15_ds_d_abs_len).average().orElse(0.0);
            Double same15DsEAvgLen = list.stream().filter(x->!StringUtils.isEmpty(x.getSameplate15_ds_e_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getSameplate15_ds_e_abs_len).average().orElse(0.0);

            Double edgeWsAAvgLen = list.stream().filter(x->!StringUtils.isEmpty(x.getEdge_ws_a_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getEdge_ws_a_abs_len).average().orElse(0.0);
            Double edgeWsBAvgLen = list.stream().filter(x->!StringUtils.isEmpty(x.getEdge_ws_b_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getEdge_ws_b_abs_len).average().orElse(0.0);
            Double edgeWsCAvgLen = list.stream().filter(x->!StringUtils.isEmpty(x.getEdge_ws_c_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getEdge_ws_c_abs_len).average().orElse(0.0);
            Double edgeWsDAvgLen = list.stream().filter(x->!StringUtils.isEmpty(x.getEdge_ws_d_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getEdge_ws_d_abs_len).average().orElse(0.0);
            Double edgeWsEAvgLen = list.stream().filter(x->!StringUtils.isEmpty(x.getEdge_ws_e_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getEdge_ws_e_abs_len).average().orElse(0.0);
            Double edgeDsAAvgLen = list.stream().filter(x->!StringUtils.isEmpty(x.getEdge_ds_a_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getEdge_ds_a_abs_len).average().orElse(0.0);
            Double edgeDsBAvgLen = list.stream().filter(x->!StringUtils.isEmpty(x.getEdge_ds_b_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getEdge_ds_b_abs_len).average().orElse(0.0);
            Double edgeDsCAvgLen = list.stream().filter(x->!StringUtils.isEmpty(x.getEdge_ds_c_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getEdge_ds_c_abs_len).average().orElse(0.0);
            Double edgeDsDAvgLen = list.stream().filter(x->!StringUtils.isEmpty(x.getEdge_ds_d_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getEdge_ds_d_abs_len).average().orElse(0.0);
            Double edgeDsEAvgLen = list.stream().filter(x->!StringUtils.isEmpty(x.getEdge_ds_e_abs_len())).mapToDouble(TbDsjC621SameEdgeResult::getEdge_ds_e_abs_len).average().orElse(0.0);
            //赋值
            //10
            steelSame.setSame10HeadMax(same10HeadMax);
            steelSame.setSame10HeadMaxColiId(same10HeadMaxColiId);
            steelSame.setSame10HeadMaxHotColiId(same10HeadMaxHotColiId);
            steelSame.setSame10HeadMin(same10HeadMin);
            steelSame.setSame10HeadMinColiId(same10HeadMinColiId);
            steelSame.setSame10HeadMinHotColiId(same10HeadMinHotColiId);
            steelSame.setSame10MidMax(same10MidMax);
            steelSame.setSame10MidMaxColiId(same10MidMaxColiId);
            steelSame.setSame10MidMaxHotColiId(same10MidMaxHotColiId);
            steelSame.setSame10MidMin(same10MidMin);
            steelSame.setSame10MidMinColiId(same10MidMinColiId);
            steelSame.setSame10MidMinHotColiId(same10MidMinHotColiId);
            steelSame.setSame10TailMax(same10TailMax);
            steelSame.setSame10TailMaxColiId(same10TailMaxColiId);
            steelSame.setSame10TailMaxHotColiId(same10TailMaxHotColiId);
            steelSame.setSame10TailMin(same10TailMin);
            steelSame.setSame10TailMinColiId(same10TailMinColiId);
            steelSame.setSame10TailMinHotColiId(same10TailMinHotColiId);
            steelSame.setSame10HeadAllLen(same10HeadAllLen);
            steelSame.setSame10HeadAvgLen(same10HeadAvgLen);
            steelSame.setSame10MidAllLen(same10MidAllLen);
            steelSame.setSame10MidAvgLen(same10MidAvgLen);
            steelSame.setSame10TailAllLen(same10TailAllLen);
            steelSame.setSame10TailAvgLen(same10TailAvgLen);
            //分等级总长
            steelSame.setSame10WsAAllLen(same10WsAAllLen);
            steelSame.setSame10WsBAllLen(same10WsBAllLen);
            steelSame.setSame10WsCAllLen(same10WsCAllLen);
            steelSame.setSame10WsDAllLen(same10WsDAllLen);
            steelSame.setSame10WsEAllLen(same10WsEAllLen);
            steelSame.setSame10DsAAllLen(same10DsAAllLen);
            steelSame.setSame10DsBAllLen(same10DsBAllLen);
            steelSame.setSame10DsCAllLen(same10DsCAllLen);
            steelSame.setSame10DsDAllLen(same10DsDAllLen);
            steelSame.setSame10DsEAllLen(same10DsEAllLen);
            //分等级均值
            steelSame.setSame10WsAAvgLen(same10WsAAvgLen);
            steelSame.setSame10WsBAvgLen(same10WsBAvgLen);
            steelSame.setSame10WsCAvgLen(same10WsCAvgLen);
            steelSame.setSame10WsDAvgLen(same10WsDAvgLen);
            steelSame.setSame10WsEAvgLen(same10WsEAvgLen);
            steelSame.setSame10DsAAvgLen(same10DsAAvgLen);
            steelSame.setSame10DsBAvgLen(same10DsBAvgLen);
            steelSame.setSame10DsCAvgLen(same10DsCAvgLen);
            steelSame.setSame10DsDAvgLen(same10DsDAvgLen);
            steelSame.setSame10DsEAvgLen(same10DsEAvgLen);
            
            //15
            steelSame.setSame15HeadMax(same15HeadMax);
            steelSame.setSame15HeadMaxColiId(same15HeadMaxColiId);
            steelSame.setSame15HeadMaxHotColiId(same15HeadMaxHotColiId);
            steelSame.setSame15HeadMin(same15HeadMin);
            steelSame.setSame15HeadMinColiId(same15HeadMinColiId);
            steelSame.setSame15HeadMinHotColiId(same15HeadMinHotColiId);
            steelSame.setSame15MidMax(same15MidMax);
            steelSame.setSame15MidMaxColiId(same15MidMaxColiId);
            steelSame.setSame15MidMaxHotColiId(same15MidMaxHotColiId);
            steelSame.setSame15MidMin(same15MidMin);
            steelSame.setSame15MidMinColiId(same15MidMinColiId);
            steelSame.setSame15MidMinHotColiId(same15MidMinHotColiId);
            steelSame.setSame15TailMax(same15TailMax);
            steelSame.setSame15TailMaxColiId(same15TailMaxColiId);
            steelSame.setSame15TailMaxHotColiId(same15TailMaxHotColiId);
            steelSame.setSame15TailMin(same15TailMin);
            steelSame.setSame15TailMinColiId(same15TailMinColiId);
            steelSame.setSame15TailMinHotColiId(same15TailMinHotColiId);
            steelSame.setSame15HeadAllLen(same15HeadAllLen);
            steelSame.setSame15HeadAvgLen(same15HeadAvgLen);
            steelSame.setSame15TailAllLen(same15TailAllLen);
            steelSame.setSame15TailAvgLen(same15TailAvgLen);
            steelSame.setSame15MidAllLen(same15MidAllLen);
            steelSame.setSame15MidAvgLen(same15MidAvgLen);
            //分等级总长
            steelSame.setSame15WsAAllLen(same15WsAAllLen);
            steelSame.setSame15WsBAllLen(same15WsBAllLen);
            steelSame.setSame15WsCAllLen(same15WsCAllLen);
            steelSame.setSame15WsDAllLen(same15WsDAllLen);
            steelSame.setSame15WsEAllLen(same15WsEAllLen);
            steelSame.setSame15DsAAllLen(same15DsAAllLen);
            steelSame.setSame15DsBAllLen(same15DsBAllLen);
            steelSame.setSame15DsCAllLen(same15DsCAllLen);
            steelSame.setSame15DsDAllLen(same15DsDAllLen);
            steelSame.setSame15DsEAllLen(same15DsEAllLen);
            //分等级均值
            steelSame.setSame15WsAAvgLen(same15WsAAvgLen);
            steelSame.setSame15WsBAvgLen(same15WsBAvgLen);
            steelSame.setSame15WsCAvgLen(same15WsCAvgLen);
            steelSame.setSame15WsDAvgLen(same15WsDAvgLen);
            steelSame.setSame15WsEAvgLen(same15WsEAvgLen);
            steelSame.setSame15DsAAvgLen(same15DsAAvgLen);
            steelSame.setSame15DsBAvgLen(same15DsBAvgLen);
            steelSame.setSame15DsCAvgLen(same15DsCAvgLen);
            steelSame.setSame15DsDAvgLen(same15DsDAvgLen);
            steelSame.setSame15DsEAvgLen(same15DsEAvgLen);
            //边降
            steelSame.setEdgeHeadMax(edgeHeadMax);
            steelSame.setEdgeHeadMaxColiId(edgeHeadMaxColiId);
            steelSame.setEdgeHeadMaxHotColiId(edgeHeadMaxHotColiId);
            steelSame.setEdgeHeadMin(edgeHeadMin);
            steelSame.setEdgeHeadMinColiId(edgeHeadMinColiId);
            steelSame.setEdgeHeadMinHotColiId(edgeHeadMinHotColiId);
            steelSame.setEdgeMidMax(edgeMidMax);
            steelSame.setEdgeMidMaxColiId(edgeMidMaxColiId);
            steelSame.setEdgeMidMaxHotColiId(edgeMidMaxHotColiId);
            steelSame.setEdgeMidMin(edgeMidMin);
            steelSame.setEdgeMidMinColiId(edgeMidMinColiId);
            steelSame.setEdgeMidMinHotColiId(edgeMidMinHotColiId);
            steelSame.setEdgeTailMax(edgeTailMax);
            steelSame.setEdgeTailMaxColiId(edgeTailMaxColiId);
            steelSame.setEdgeTailMaxHotColiId(edgeTailMaxHotColiId);
            steelSame.setEdgeTailMin(edgeTailMin);
            steelSame.setEdgeTailMinColiId(edgeTailMinColiId);
            steelSame.setEdgeTailMinHotColiId(edgeTailMinHotColiId);
            steelSame.setEdgeHeadAllLen(edgeHeadAllLen);
            steelSame.setEdgeHeadAvgLen(edgeHeadAvgLen);
            steelSame.setEdgeMidAllLen(edgeMidAllLen);
            steelSame.setEdgeMidAvgLen(edgeMidAvgLen);
            steelSame.setEdgeTailAllLen(edgeTailAllLen);
            steelSame.setEdgeTailAvgLen(edgeTailAvgLen);
            //分等级总长
            steelSame.setEdgeWsAAllLen(edgeWsAAllLen);
            steelSame.setEdgeWsBAllLen(edgeWsBAllLen);
            steelSame.setEdgeWsCAllLen(edgeWsCAllLen);
            steelSame.setEdgeWsDAllLen(edgeWsDAllLen);
            steelSame.setEdgeWsEAllLen(edgeWsEAllLen);
            steelSame.setEdgeDsAAllLen(edgeDsAAllLen);
            steelSame.setEdgeDsBAllLen(edgeDsBAllLen);
            steelSame.setEdgeDsCAllLen(edgeDsCAllLen);
            steelSame.setEdgeDsDAllLen(edgeDsDAllLen);
            steelSame.setEdgeDsEAllLen(edgeDsEAllLen);
            //分等级均值
            steelSame.setEdgeWsAAvgLen(edgeWsAAvgLen);
            steelSame.setEdgeWsBAvgLen(edgeWsBAvgLen);
            steelSame.setEdgeWsCAvgLen(edgeWsCAvgLen);
            steelSame.setEdgeWsDAvgLen(edgeWsDAvgLen);
            steelSame.setEdgeWsEAvgLen(edgeWsEAvgLen);
            steelSame.setEdgeDsAAvgLen(edgeDsAAvgLen);
            steelSame.setEdgeDsBAvgLen(edgeDsBAvgLen);
            steelSame.setEdgeDsCAvgLen(edgeDsCAvgLen);
            steelSame.setEdgeDsDAvgLen(edgeDsDAvgLen);
            steelSame.setEdgeDsEAvgLen(edgeDsEAvgLen);

            return ResultData.ResultDataSuccess(list, count, steelSame,listForPage);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultData.ResultDataFaultSelf("查询失败,失败信息为" + e.getMessage(), null);
        }

    }




    /**
     * 根据卷号查询对应长度归档数据曲线
     * @param volumeNo
     * @return
     */
    public ResultData findSameEdgeByVolumeNo621(List<String> volumeNo){
        if(CollectionUtils.isEmpty(volumeNo)){
            return ResultData.ResultDataFaultSelf(null,"传入卷号为空");
        }

        Map<String, Map<String,Object>> map = new HashMap<>();
        Query query1=new Query(Criteria.where("extid").in(volumeNo));
//        List<JDataSave621> list = mongoTemplate.find(query1, JDataSave621.class);
        List<TbEdge> list = mongoTemplate.find(query1, TbEdge.class);

        Query query = new Query(Criteria.where("extid").in(volumeNo));
        List<JDataSave621> jDataSave621List = mongoTemplate.find(query, JDataSave621.class);

        for (TbEdge tbEdge : list) {
            Map<String,Object> mapValue = new HashMap<>();
//            Query query=new Query(Criteria.where("extid").is(no));
//            JDataSave621 jDataSave621 = mongoTemplate.findOne(query, JDataSave621.class);
            Object list1 =  tbEdge.getEdge().get("edge_thick_center");
            Object list2=  tbEdge.getEdge().get("edge_thick_DS_15");
            Object list3 =  tbEdge.getEdge().get("edge_thick_DS_115");
            Object list4 =  tbEdge.getEdge().get("edge_thick_WS_15");
            Object list5 =  tbEdge.getEdge().get("edge_thick_WS_115");
            Object list6 =  tbEdge.getEdge().get("edge_thick_WS_10");
            Object list7 =  tbEdge.getEdge().get("edge_thick_DS_10");
            Object list8 =  tbEdge.getEdge().get("edge_thick_DS_5");
            Object list9 =  tbEdge.getEdge().get("edge_thick_DS_30");
            Object list10 =  tbEdge.getEdge().get("edge_thick_DS_40");
            Object list11 =  tbEdge.getEdge().get("edge_thick_DS_50");
            Object list12 =  tbEdge.getEdge().get("edge_thick_DS_60");
            Object list13 =  tbEdge.getEdge().get("edge_thick_DS_70");
            Object list14 =  tbEdge.getEdge().get("edge_thick_DS_80");
            Object list15 =  tbEdge.getEdge().get("edge_thick_DS_90");
            Object list16 =  tbEdge.getEdge().get("edge_thick_DS_100");
            Object list17 =  tbEdge.getEdge().get("edge_thick_DS_120");
            Object list18 =  tbEdge.getEdge().get("edge_thick_DS_130");
            Object list19 =  tbEdge.getEdge().get("edge_thick_WS_5");
            Object list20 =  tbEdge.getEdge().get("edge_thick_WS_30");
            Object list21 =  tbEdge.getEdge().get("edge_thick_WS_40");
            Object list22 =  tbEdge.getEdge().get("edge_thick_WS_50");
            Object list23 =  tbEdge.getEdge().get("edge_thick_WS_60");
            Object list24 =  tbEdge.getEdge().get("edge_thick_WS_70");
            Object list25 =  tbEdge.getEdge().get("edge_thick_WS_80");
            Object list26 =  tbEdge.getEdge().get("edge_thick_WS_90");
            Object list27 =  tbEdge.getEdge().get("edge_thick_WS_100");
            Object list28 =  tbEdge.getEdge().get("edge_thick_WS_120");
            Object list29 =  tbEdge.getEdge().get("edge_thick_WS_130");


            mapValue.put("edge_thick_center",list1);
            mapValue.put("edge_thick_DS_15",list2);
            mapValue.put("edge_thick_DS_115",list3);
            mapValue.put("edge_thick_WS_15",list4);
            mapValue.put("edge_thick_WS_115",list5);
            mapValue.put("edge_thick_WS_10",list6);
            mapValue.put("edge_thick_DS_10",list7);
            mapValue.put("edge_thick_DS_5",list8);
            mapValue.put("edge_thick_DS_30",list9);
            mapValue.put("edge_thick_DS_40",list10);
            mapValue.put("edge_thick_DS_50",list11);
            mapValue.put("edge_thick_DS_60",list12);
            mapValue.put("edge_thick_DS_70",list13);
            mapValue.put("edge_thick_DS_80",list14);
            mapValue.put("edge_thick_DS_90",list15);
            mapValue.put("edge_thick_DS_100",list16);
            mapValue.put("edge_thick_DS_120",list17);
            mapValue.put("edge_thick_DS_130",list18);
            mapValue.put("edge_thick_WS_5",list19);
            mapValue.put("edge_thick_WS_30",list20);
            mapValue.put("edge_thick_WS_40",list21);
            mapValue.put("edge_thick_WS_50",list22);
            mapValue.put("edge_thick_WS_60",list23);
            mapValue.put("edge_thick_WS_70",list24);
            mapValue.put("edge_thick_WS_80",list25);
            mapValue.put("edge_thick_WS_90",list26);
            mapValue.put("edge_thick_WS_100",list27);
            mapValue.put("edge_thick_WS_120",list28);
            mapValue.put("edge_thick_WS_130",list29);


//			List<Double> list = jDataSave621.getRow().get("c621_pl_pl1_level_correction_realtime");
            String extid = tbEdge.getExtid();
            if(StringUtils.hasText(extid)){
                map.put(extid,mapValue);
            }
        }

        for (JDataSave621 jDataSave621 : jDataSave621List) {
            Map<String,Object> mapValue = new HashMap<>();
            List<Double> list1 = jDataSave621.getRow().get("c621_tcm_s1_up_wr_shifting_act");
            List<Double> list2 = jDataSave621.getRow().get("c621_tcm_s1_dw_wr_shifting_act");
            List<Double> list3 = jDataSave621.getRow().get("c621_tcm_s2_up_wr_shifting_act");
            List<Double> list4 = jDataSave621.getRow().get("c621_tcm_s2_dw_wr_shifting_act");
            mapValue.put("c621_tcm_s1_up_wr_shifting_act",list1);
            mapValue.put("c621_tcm_s1_dw_wr_shifting_act",list2);
            mapValue.put("c621_tcm_s2_up_wr_shifting_act",list3);
            mapValue.put("c621_tcm_s2_dw_wr_shifting_act",list4);

            String extid = jDataSave621.getExtid();
            if (StringUtils.hasText(extid)) {
                map.put(extid,mapValue);
            }
        }
        if(!CollectionUtils.isEmpty(map)){
            return ResultData.ResultDataSuccess(map);
        }
        return ResultData.ResultDataFaultSelf(null,"查询数据为空");
    }

    public void export(JSONObject jsonObject, HttpServletResponse response) {
        // 接收传入参数
        Integer pageSize = jsonObject.getInteger("pageSize");
        Integer pageCount = jsonObject.getInteger("pageCount");
        String fileNames = jsonObject.getString("fileName");
        JSONObject condition = jsonObject.getJSONObject("condition");String dbegin = null; //开始时间
        LambdaQueryWrapper<TbDsjC621SameEdgeResult> wrapper = new LambdaQueryWrapper<>();
        if (StringUtils.hasText(condition.getString("dbegin"))) {
            dbegin = condition.getString("dbegin");
            wrapper.ge(TbDsjC621SameEdgeResult::getCreatetime, dbegin);
        }
        String dend = null; //结束时间
        if (StringUtils.hasText(condition.getString("dend"))) {
            dend = condition.getString("dend");
            wrapper.le(TbDsjC621SameEdgeResult::getCreatetime, dend);
        }

        String coil_id = null;
        if (StringUtils.hasText(condition.getString("coil_id"))) {
            coil_id = condition.getString("coil_id");
            wrapper.like(TbDsjC621SameEdgeResult::getCoil_id, coil_id);
        }

        String hot_id = null;
        if (StringUtils.hasText(condition.getString("hot_id"))) {
            hot_id = condition.getString("hot_id");
            wrapper.like(TbDsjC621SameEdgeResult::getHot_coil_id, hot_id);
        }

        String ex_thk1 = null;  //产品厚度----开始
        if (StringUtils.hasText(condition.getString("ex_thk1"))) {
            ex_thk1 = condition.getString("ex_thk1");
            wrapper.ge(TbDsjC621SameEdgeResult::getEx_thk, ex_thk1);
        }

        String ex_thk2 = null;  //产品厚度---结束
        if (StringUtils.hasText(condition.getString("ex_thk2"))) {
            ex_thk2 = condition.getString("ex_thk2");
            wrapper.le(TbDsjC621SameEdgeResult::getEx_thk, ex_thk2);
        }

        String en_wid1 = null;  //原料宽度----开始
        if (StringUtils.hasText(condition.getString("en_wid1"))) {
            en_wid1 = condition.getString("en_wid1");
            wrapper.ge(TbDsjC621SameEdgeResult::getEn_wid, en_wid1);
        }


        String en_wid2 = null;  //原料宽度----结束
        if (StringUtils.hasText(condition.getString("en_wid2"))) {
            en_wid2 = condition.getString("en_wid2");
            wrapper.le(TbDsjC621SameEdgeResult::getEn_wid, en_wid2);

        }

        String en_thk1 = null;  //原料厚度----开始
        if (StringUtils.hasText(condition.getString("en_thk1"))) {
            en_thk1 = condition.getString("en_thk1");
            wrapper.ge(TbDsjC621SameEdgeResult::getEn_thk, en_thk1);
        }

        String en_thk2 = null;  //原料厚度----结束
        if (StringUtils.hasText(condition.getString("en_thk2"))) {
            en_thk2 = condition.getString("en_thk2");
            wrapper.le(TbDsjC621SameEdgeResult::getEn_thk, en_thk2);
        }

        String ele_si1 = null;  //硅含量---开始
        if (StringUtils.hasText(condition.getString("ele_si1"))) {
            ele_si1 = condition.getString("ele_si1");
            wrapper.ge(TbDsjC621SameEdgeResult::getEle_si, ele_si1);
        }
        String ele_si2 = null;  //硅含量---结束
        if (StringUtils.hasText(condition.getString("ele_si2"))) {
            ele_si2 = condition.getString("ele_si2");
            wrapper.le(TbDsjC621SameEdgeResult::getEle_si, ele_si2);
        }

        String steelgrade = null;  //钢种
        if (StringUtils.hasText(condition.getString("steelgrade"))) {
            steelgrade = condition.getString("steelgrade");
            wrapper.eq(TbDsjC621SameEdgeResult::getSteelgrade, steelgrade);
        }
        wrapper.orderByDesc(TbDsjC621SameEdgeResult::getCreatetime);
        List<TbDsjC621SameEdgeResult> listExcel = tbDsjC621SameEdgeResultDao.selectList(wrapper);
        if (CollectionUtils.isEmpty(listExcel)) {
            return;
        }
        List<ExportTbDsjC621SameEdgeResult> list = new ArrayList<>();
        if (!listExcel.isEmpty() && listExcel.size() > 0) {
            for (TbDsjC621SameEdgeResult item : listExcel) {
                ExportTbDsjC621SameEdgeResult exportTbDsjC621SameEdgeResult = new ExportTbDsjC621SameEdgeResult();
                BeanUtils.copyProperties(item,exportTbDsjC621SameEdgeResult);
                list.add(exportTbDsjC621SameEdgeResult);
            }
        }
        String classpath="";
        if(fileNames.equals("同板差-边降头尾超差"))
        {
            classpath="classpath:exceltemplate\\同板差边降头尾超差.xlsx";
        }
        if(fileNames.equals("同板差-边降等级"))
        {
            classpath="classpath:exceltemplate\\同板差边降等级.xlsx";
        }
        try {
            Map<String,Object> data = new HashMap();
            data.put("data",list);
            File file = ResourceUtils.getFile(classpath);
            TemplateExportParams templateExportParams = new TemplateExportParams(file.getPath(),false);
            templateExportParams.setDictHandler(new PlanExcelHandlerImpl());
            Workbook workbook = ExcelExportUtil.exportExcel(templateExportParams, data);
            ExcelUtilsPOI.exportExcel(fileNames,response,workbook);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        //ExcelUtils.downloadExcel(fileNames,response, TbDsjC621SameEdgeResult.class,listExcel);
    }


    public void exportold(JSONObject jsonObject, HttpServletResponse response) {
        // 接收传入参数
        Integer pageSize = jsonObject.getInteger("pageSize");
        Integer pageCount = jsonObject.getInteger("pageCount");
        String fileNames = jsonObject.getString("fileName");
        JSONObject condition = jsonObject.getJSONObject("condition");String dbegin = null; //开始时间
        LambdaQueryWrapper<TbDsjC621SameEdgeResult> wrapper = new LambdaQueryWrapper<>();
        if (StringUtils.hasText(condition.getString("dbegin"))) {
            dbegin = condition.getString("dbegin");
            wrapper.ge(TbDsjC621SameEdgeResult::getCreatetime, dbegin);
        }
        String dend = null; //结束时间
        if (StringUtils.hasText(condition.getString("dend"))) {
            dend = condition.getString("dend");
            wrapper.le(TbDsjC621SameEdgeResult::getCreatetime, dend);
        }

        String coil_id = null;
        if (StringUtils.hasText(condition.getString("coil_id"))) {
            coil_id = condition.getString("coil_id");
            wrapper.like(TbDsjC621SameEdgeResult::getCoil_id, coil_id);
        }

        String hot_id = null;
        if (StringUtils.hasText(condition.getString("hot_id"))) {
            hot_id = condition.getString("hot_id");
            wrapper.like(TbDsjC621SameEdgeResult::getHot_coil_id, hot_id);
        }

        String ex_thk1 = null;  //产品厚度----开始
        if (StringUtils.hasText(condition.getString("ex_thk1"))) {
            ex_thk1 = condition.getString("ex_thk1");
            wrapper.ge(TbDsjC621SameEdgeResult::getEx_thk, ex_thk1);
        }

        String ex_thk2 = null;  //产品厚度---结束
        if (StringUtils.hasText(condition.getString("ex_thk2"))) {
            ex_thk2 = condition.getString("ex_thk2");
            wrapper.le(TbDsjC621SameEdgeResult::getEx_thk, ex_thk2);
        }

        String en_wid1 = null;  //原料宽度----开始
        if (StringUtils.hasText(condition.getString("en_wid1"))) {
            en_wid1 = condition.getString("en_wid1");
            wrapper.ge(TbDsjC621SameEdgeResult::getEn_wid, en_wid1);
        }


        String en_wid2 = null;  //原料宽度----结束
        if (StringUtils.hasText(condition.getString("en_wid2"))) {
            en_wid2 = condition.getString("en_wid2");
            wrapper.le(TbDsjC621SameEdgeResult::getEn_wid, en_wid2);

        }

        String en_thk1 = null;  //原料厚度----开始
        if (StringUtils.hasText(condition.getString("en_thk1"))) {
            en_thk1 = condition.getString("en_thk1");
            wrapper.ge(TbDsjC621SameEdgeResult::getEn_thk, en_thk1);
        }

        String en_thk2 = null;  //原料厚度----结束
        if (StringUtils.hasText(condition.getString("en_thk2"))) {
            en_thk2 = condition.getString("en_thk2");
            wrapper.le(TbDsjC621SameEdgeResult::getEn_thk, en_thk2);
        }

        String ele_si1 = null;  //硅含量---开始
        if (StringUtils.hasText(condition.getString("ele_si1"))) {
            ele_si1 = condition.getString("ele_si1");
            wrapper.ge(TbDsjC621SameEdgeResult::getEle_si, ele_si1);
        }
        String ele_si2 = null;  //硅含量---结束
        if (StringUtils.hasText(condition.getString("ele_si2"))) {
            ele_si2 = condition.getString("ele_si2");
            wrapper.le(TbDsjC621SameEdgeResult::getEle_si, ele_si2);
        }

        String steelgrade = null;  //钢种
        if (StringUtils.hasText(condition.getString("steelgrade"))) {
            steelgrade = condition.getString("steelgrade");
            wrapper.eq(TbDsjC621SameEdgeResult::getSteelgrade, steelgrade);
        }
        wrapper.orderByDesc(TbDsjC621SameEdgeResult::getCreatetime);
        List<TbDsjC621SameEdgeResult> listExcel = tbDsjC621SameEdgeResultDao.selectList(wrapper);
        if (CollectionUtils.isEmpty(listExcel)) {
            return;
        }
        ExcelUtils.downloadExcel(fileNames,response, TbDsjC621SameEdgeResult.class,listExcel);
    }
    public ResultData findByCurce(JSONObject jsonObject) {
        // 接收前端传入参数
        String extid = jsonObject.getString("extid");
        Double mi = jsonObject.getDouble("mi");
        Double miCount = jsonObject.getDouble("miCount");

        // 使用卷号去hot_crown集合中查询
        Query query = new Query(Criteria.where("extid").is(extid));
        List<HotCrown> hotCrowns = mongoTemplate.find(query, HotCrown.class);
        List<Object> numList = new ArrayList<>();
        for (HotCrown item : hotCrowns) {
            Map<String, List<Double>> cw = item.getCw();
            List<Double> list1 = cw.get("thk_ws25");
            Double num = getNum(mi, miCount, list1);
            List<Double> list2 = cw.get("thk_ws40");
            Double num1 = getNum(mi, miCount, list2);
            List<Double> list3 = cw.get("thk_ws70");
            Double num2 = getNum(mi, miCount, list3);
            List<Double> list4 = cw.get("thk_ws100");
            Double num3 = getNum(mi, miCount, list4);
            List<Double> list5 = cw.get("thk_ds100");
            Double num4 = getNum(mi, miCount, list5);
            List<Double> list6 = cw.get("thk_ds70");
            Double num5 = getNum(mi, miCount, list6);
            List<Double> list7 = cw.get("thk_ds25");
            Double num6 = getNum(mi, miCount, list7);
            List<Double> list8 = cw.get("thk_ds40");
            Double num7 = getNum(mi, miCount, list8);
            List<Double> list9 = cw.get("thk_center");
            Double num8 = getNum(mi, miCount, list9);
            numList.add(0,0);
            numList.add(1,0);
            numList.add(2,0);
            numList.add(3,num);
            numList.add(4,num1);
            numList.add(5,0);
            numList.add(6,0);
            numList.add(7,num2);
            numList.add(8,0);
            numList.add(9,0);
            numList.add(10,num3);
            numList.add(11,0);
            numList.add(12,0);
            numList.add(13,0);
            numList.add(14,num8);
            numList.add(15,0);
            numList.add(16,0);
            numList.add(17,0);
            numList.add(18,num4);
            numList.add(19,0);
            numList.add(20,0);
            numList.add(21,num5);
            numList.add(22,0);
            numList.add(23,0);
            numList.add(24,num7);
            numList.add(25,num6);
            numList.add(26,0);
            numList.add(27,0);
            numList.add(28,0);
        }
        return ResultData.ResultDataFaultSelf("操作成功",numList);
    }

    private Double getNum(Double mi, Double miCount, List<Double> list) {
        if (list.isEmpty()) {
            return 0.0;
        }
        Double floor = (mi / miCount) * list.size();
        String str = Math.floor(floor) + "";
        String[] split = str.split("\\.");
        return list.get(Integer.parseInt(split[0]));
    }
}






